package com.sky.mapper.user;

import com.sky.pojo.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AddressBookMapper {
    /**
     * 查询当前登录用户的所有地址信息
     */
    @Select("select* from address_book where user_id = #{userId}")
    List<AddressBook> queryAll(Long userId);

    /**
     * 查询默认地址
     */
    @Select("select * from address_book where user_id = #{userId} and is_default = 1")
    AddressBook queryDefault(Long userId);

    AddressBook query(AddressBook addressBook);

    @Insert("insert into address_book (user_id,consignee,sex,phone,province_code,province_name,city_code,city_name,district_code,district_name,detail,label,is_default)" +
            "values (#{userId},#{consignee},#{sex},#{phone},#{provinceCode},#{provinceName},#{cityCode},#{cityName},#{districtCode},#{districtName},#{detail},#{label},#{isDefault})")
    void insert(AddressBook addressBook);

    @Delete("delete from address_book where id = #{id}")
    void delete(Long id);

    void update(AddressBook addressBook);
}
